package com.example.boke.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.io.Encoders;
import io.jsonwebtoken.security.Keys;
import lombok.extern.slf4j.Slf4j;

import java.security.Key;
import java.util.Date;
import java.util.Map;
@Slf4j
public class JwtUtils {
    public static final long Expiration=30*60*1000;
  static   Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
    String secretString = Encoders.BASE64.encode(key.getEncoded());
    public static String genJwtToken(Map<String, Object> claim){
        String token = Jwts.builder().setClaims(claim)
                .setExpiration(new Date(System.currentTimeMillis()+Expiration))
                .signWith(key)
                .compact();
        return token;
    }
public static Claims parseToken(String token){
    JwtParser build = Jwts.parserBuilder().setSigningKey(key).build();
    Claims claims = null;
    try{
        claims = build.parseClaimsJws(token).getBody();
    }
    catch (Exception e){
        log.info("解析token失败");
        return claims;
    }
    return claims;
}



}
